# -*- coding: utf-8 -*-
# @Time : 2024/4/30 14:11
# @Author : Zxg
# @Email : 1473858993@qq.com
# @File : logutils.py
# @Project : Luckin_Finance_UI


import logging
from common.dir import log_dir
import os.path


class LoggingUtil:
    def __init__(self, filename):
        # 获取一个log对象
        logger = logging.getLogger()
        # 总日志级别
        logger.setLevel(logging.INFO)
        # 日志存放位置
        filepath = os.path.join(log_dir, filename)
        # 文件处理器handler
        handler = logging.FileHandler(filepath, mode='a+', encoding='utf-8')
        # 格式器
        fromatter = logging.Formatter('[%(levelname)s %(filename)s %(asctime)s ]  --> %(message)s <--  %(lineno)d')
        # 设置日志输出格式
        handler.setFormatter(fromatter)
        # 添加haddler
        logger.addHandler(handler)
